package logic

import (
	"cart_srv/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HandlerCartAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHandlerCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HandlerCartAddLogic {
	return &HandlerCartAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HandlerCartAddLogic) HandlerCartAdd(req *types.RequestCartAdd) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.CartSrv.CartAdd(l.ctx, &cart.CartAddRequest{
		UserId:     int32(req.UserId),
		GoodsId:    int32(req.GoodsId),
		Quantity:   int32(req.Quantity),
		GoodsName:  req.GoodsName,
		GoodsPrice: float32(req.GoodsPrice),
		Status:     int32(req.Status),
	})
	if err != nil {
		return &types.Response{
			Msg:  "添加失败",
			Code: "500",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "添加成功",
		Code: "200",
		Data: add,
	}, nil
}
